/**
 * Copyright (c) Software Institute of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.actions;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;

import edu.pku.sei.modeler.model.core.MetaNamedElement;
/**
 * @author zl,zy
 *
 */
public class NodeRenameAction extends Action {
	IWorkbenchPage workbenchPage;
	private Object obj;
	
	public IWorkbenchPage getWorkbenchPage() {
		return workbenchPage;
	}
	public void setTreeObj(Object obj) {
		this.obj = obj;
	}
	public void setWorkbenchPage(IWorkbenchPage workbenchPage) {
		this.workbenchPage = workbenchPage;
	}
	public NodeRenameAction(){
		super();
		this.setText("Rename");
		setToolTipText("Rename the selected node");
		this.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
				getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
	}
	public void run(){
		if(obj==null)return;
		if(obj instanceof MetaNamedElement){
			MetaNamedElement object= (MetaNamedElement)obj;
			InputDialog dialog = new InputDialog(null,"Rename","Input the new name",object.getName(),null);
			if(dialog.open()==InputDialog.OK){
				String newName = dialog.getValue();
				object.setName(newName);
			}
			if(this.getWorkbenchPage()==null) return;
		}
	}
}
